<script setup lang="ts">
import { getClassList } from '@/api/class';
import type { Class } from '@/api/class/type';
import { onMounted, ref } from 'vue';
import BindDevice from './components/BindDevice.vue';

const classList = ref([] as Class[]);
const showBindDevice = ref(false);
const classId = ref('');
onMounted(() => {
    getClassList().then((res) => {
        classList.value = res.data;
    });
})

const bind = (id: string) => {
    classId.value = id;
    showBindDevice.value = true;
}

</script>

<template>
    <div class="content">
        <div class="header">
            <el-button type="primary">创建班级</el-button>
        </div>
        <el-table :data="classList" style="width: 100%" stripe border>
            <el-table-column prop="id" label="班级ID" />
            <el-table-column prop="name" label="班级名" />
            <el-table-column prop="creator" label="创建者" />
            <el-table-column prop="created" label="创建时间" />
            <el-table-column prop="updated" label="更新时间" />
            <el-table-column fixed="right" label="操作" min-width="120">
                <template #default="scope">
                    <el-button link type="primary" size="small" @click="bind(scope.row.id)">绑定机器</el-button>
                </template>
            </el-table-column>
        </el-table>
        <BindDevice v-if="showBindDevice" v-model="showBindDevice" v-model:class-id="classId"></BindDevice>
    </div>
</template>

<style lang="scss" scoped>
.header {
    margin-bottom: 1%;
}
</style>